<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
    />
    <meta name="author" content="林镭特" />
    <title></title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
      .progress {
        display: flex;
      }
      .progress span {
        margin-right: 10px;
      }
      .slider-box {
        position: relative;
        width: 200px;
        height: 5px;
      }
      .slider-bar {
        position: absolute;
        top: 10px;
        height: 5px;
        width: 100%;
        -webkit-border-radius: 10px;
        -moz-border-radius: 10px;
        border-radius: 10px;
        background-color: #e6e6e8;
      }
      .slider-value {
        height: 100%;
        width: 0;
        -webkit-border-radius: 10px;
        -moz-border-radius: 10px;
        border-radius: 10px;
        background-color: #e83c3c;
      }
      .slider-ball {
        position: absolute;
        top: -3px;
        left: -5px;
        width: 10px;
        height: 10px;
        -webkit-border-radius: 50%;
        -moz-border-radius: 50%;
        border-radius: 50%;
        background-color: #fff;
        border: 1px solid #999;
      }
    </style>
  </head>
  <body>
    <div id="app">

        <input type="text" v-model="count" >

      <my-div :value="count"  @input="count = $event;" ></my-div>
    </div>

    <script id="my-div" type="text/html">

      <div class="progress time">
          <span class="timeValue">0</span>
          <div class="slider-box">
              <div class="slider-bar"

              @mousedown="sliderMove($event,this)"  
              @click="send($event,this)"
                   >
                  <div class="slider-value">
                      <div class="slider-ball"></div>
                  </div>
              </div>
          </div>
      </div>
    </script>

    <script>
      var rate;
      var timeFlag = true;

      Vue.component("my-div", {
        template: "#my-div",
        props:['value'],
        data() {
          return {};
        },
        methods: {
          sliderMove(ev, _this) {
            if (timeFlag) {
                rate=this.value
              var timeBar = document.querySelector(".time .slider-bar");
              var timevall = document.querySelector(".time .slider-value");
              var timeBall = document.querySelector(".time .slider-ball");
              var timeValue = document.querySelector(".timeValue");
               var rate=this.value
              console.log(rate);
              move(ev, timeBar);

              function move(ev, progressElement) {
                // console.log(progressElement);
                var barRect = progressElement.getBoundingClientRect();

               
                // console.log(barRect);
                var boundary = ev.pageX - barRect.left;
                boundary =
                  boundary > barRect.width
                    ? barRect.width
                    : boundary < 0
                    ? 0
                    : boundary;
                rate = boundary / barRect.width; // 点击比例
              value=rate
            
                console.log(rate);
                var value = timevall;
                var ball = timeBall;
                value.style.width = rate * 100 + "%";
                ball.style.left = rate * 100 - 3 + "%";
                // 改变文本
                if (ball === timeBall) {
                  timeValue.innerHTML = rate.toFixed(2);
                }
              }
            }
          },
          send(ev){
           
              var timeBar = document.querySelector(".time .slider-bar");
            
               var rate=this.value
              console.log(rate);
              move(ev, timeBar);

              function move(ev, progressElement) {
                // console.log(progressElement);
                var barRect = progressElement.getBoundingClientRect();
                // console.log(barRect);
                var boundary = ev.pageX - barRect.left;
                boundary =
                  boundary > barRect.width
                    ? barRect.width
                    : boundary < 0
                    ? 0
                    : boundary;
                rate = boundary / barRect.width; // 点击比例
              value=rate
             this.$emit('input',value )
              
              }
          }



        },
      });

      let app = new Vue({
        el: "#app",
        data: {
            count:0
        },
      });
    </script>
  </body>
</html>
